const util = require("../../utils/util.js");
Page({
    data:{
        users : [],
        userItems: [{
          icon: '../../images/iconfont/iconfont-dingdan.png',
          text: '开通会员',
          isunread:false,
          unreadNum: 3
        }, {
            icon: '../../images/iconfont/iconfont-card.png',
          text: '平台配置',
          isunread: false,
          unreadNum: 2
        }, {
            icon: '../../images/iconfont/iconfont-icontuan.png',
            text: '联系客服',
          isunread: false,
          unreadNum: 1
        }]
    },
    onLoad:function(options){
        util.showLoading();
        var that = this;
        wx.getStorage({
          key: 'USERS',
          success: function(res) {
            that.setData({
              users:res.data
            });
            if (!that.data.users.nickname){
              wx.getUserInfo({
                withCredentials: true,
                lang: "zh_CN",
                success: function (res) {
                  util.wxPost({
                    url: "/rest/muser", params: {
                      "id": that.data.users.id,
                      "nickName": res.userInfo.nickName,
                      "avatarUrl": res.userInfo.avatarUrl,
                      "gender": res.userInfo.gender
                    },
                    success: function (data) {
                      if (data.data.status == "000") {
                        that.setData({
                          users: data.data.data
                        });
                        wx.setStorage({
                          key: 'USERS',
                          data: data.data.data
                        });
                      }
                    }
                  });
                }
              });
            }
          }
        });
        util.hideToast();
    },
    //登录
    taplogin:function(){
        wx.navigateTo({
        url: '../login/login',
        success: function(res){
          // success
        },
        fail: function() {
          // fail
        },
        complete: function() {
          // complete
        }
      })
    },
    onPullDownRefresh:function(){
      console.log("ddddddddddddd");
    }


});